package com.UI;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.Adapter.GolfDbAdapter;
import com.UI.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class GolfNamesActivity extends Activity {	
		 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.names);
        
        final GolfDbAdapter mDbHelper = new GolfDbAdapter(this);
    
        Button confirmButton = (Button) findViewById(R.id.ButtonSend);
        
        confirmButton.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View view) {
        	 	
         		EditText txtTeamA = (EditText)findViewById(R.id.txtTeamA);
         		EditText txtTeamB = (EditText)findViewById(R.id.txtTeamB);
        		EditText txtTeamAPlayer1 = (EditText)findViewById(R.id.TeamAPlayer1);
        		EditText txtTeamAPlayer2 = (EditText)findViewById(R.id.TeamAPlayer2);
        		EditText txtTeamBPlayer1 = (EditText)findViewById(R.id.TeamBPlayer1);
        		EditText txtTeamBPlayer2 = (EditText)findViewById(R.id.TeamBPlayer2);
//        		EditText txtPointValue = (EditText)findViewById(R.id.pointValue);
        		
        		String strTeamA = txtTeamA.getText().toString();
        		String strTeamB = txtTeamB.getText().toString();
        		String strTeamAPlayer1 = txtTeamAPlayer1.getText().toString();
        		String strTeamAPlayer2 = txtTeamAPlayer2.getText().toString();
        		String strTeamBPlayer1 = txtTeamBPlayer1.getText().toString();
        		String strTeamBPlayer2 = txtTeamBPlayer2.getText().toString();
 //       		String strPointValue = txtPointValue.getText().toString();
 //       		float pointValue = Float.parseFloat(strPointValue);
         		
        		// make sure all fields are filled in       		       		
//        		if(strTeamA.length() == 0 || strTeamB.length() == 0 || 
//        		   strTeamAPlayer1.length() == 0 || strTeamAPlayer2.length() == 0 ||
//        		   strTeamBPlayer1.length() == 0 || strTeamBPlayer2.length() == 0 ) {
//	        	      
//	        		   AlertDialog alertDialog = new AlertDialog.Builder(GolfNamesActivity.this).create();	        			
//	        		   alertDialog.setTitle("Warning");	        		  
//	        		   alertDialog.setMessage("All fields must be filled in!");	        		  	        		  
//	        		   alertDialog.setButton("OK", new DialogInterface.OnClickListener() {	       		  
//	        		     public void onClick(DialogInterface dialog, int which) {     		  
//     		                return;     		  
//     		             } }); 
//     		  
//     		              alertDialog.show();
//     		  
//     		     }
//        		
//        	     else {
        			
        			final ContentValues namesA = new ContentValues();
        			final ContentValues namesB = new ContentValues();
        			
        			// convert first letter to upper-case and rest to lower-case
//        			String TeamA = strTeamA.substring(0,1).toUpperCase() + strTeamA.substring(1).toLowerCase(); 
//            		String TeamB = strTeamB.substring(0,1).toUpperCase() + strTeamB.substring(1).toLowerCase(); 
//            		String TeamAPlayer1 = strTeamAPlayer1.substring(0,1).toUpperCase() + strTeamAPlayer1.substring(1).toLowerCase(); 
//            		String TeamAPlayer2 = strTeamAPlayer2.substring(0,1).toUpperCase() + strTeamAPlayer2.substring(1).toLowerCase(); 
//            		String TeamBPlayer1 = strTeamBPlayer1.substring(0,1).toUpperCase() + strTeamBPlayer1.substring(1).toLowerCase(); 
//            		String TeamBPlayer2 = strTeamBPlayer2.substring(0,1).toUpperCase() + strTeamBPlayer2.substring(1).toLowerCase();       			        			
        			
            		java.util.Date date = Calendar.getInstance().getTime();
            		SimpleDateFormat df = new SimpleDateFormat("MMM dd,yyyy"); 
            		String todaysDate = df.format(date);
            	
//            		namesA.put("day", todaysDate);
//	        		namesA.put("teamName", TeamA);	        		
//	        		namesA.put("playerOne", TeamAPlayer1);
//	        		namesA.put("playerTwo", TeamAPlayer2);
//	        		
//	        		mDbHelper.addNewTeam(namesA);
//	        		
//	        		namesB.put("day", todaysDate);
//	        		namesB.put("teamName", TeamB);
//	        		namesB.put("playerOne", TeamBPlayer1);
//	        		namesB.put("playerTwo", TeamBPlayer2);
//	        		
//	        		mDbHelper.addNewTeam(namesB);
	        		
	        		
	         		namesA.put("day", todaysDate);
	        		namesA.put("teamName", "Krons");	        		
	        		namesA.put("playerOne", "Brian");
	        		namesA.put("playerTwo", "Derek");
	        		
	        		mDbHelper.addNewTeam(namesA);
	        		
	        		namesB.put("day", todaysDate);
	        		namesB.put("teamName", "Bros");
	        		namesB.put("playerOne", "Harv");
	        		namesB.put("playerTwo", "Den");
	        		
	        		mDbHelper.addNewTeam(namesB);
	        			        	      			
	        		//once the data is entered, direct the user to the select courses page
	        		Intent viewCourse = new Intent(GolfNamesActivity.this, GolfCoursesActivity.class);
					startActivity(viewCourse);
					
        			
        		}       	
  //      	}         
        });            
   }    

}